-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Messenger] get()
usage
#11889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Messenger] get()
usage
#11889
Conversation
components/messenger.rst
Outdated
|
||
return [$envelope]; | ||
|
||
// Reject the message if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment ... should we add another (commented) line of code showing how to reject the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is linked to the transport, I don't know if we can find a generic approach, I've added one if you want to check it 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I can't review because I don't understand this ... but as a reader, the comment was strange because it was like "you can reject the message if you want" OK but here? now? how? is the comment related to the following return? Returning means rejecting? etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok, sorry for the wording.
As get()
allows you to receive a message and decide if you want to send it to the application, reject it or ack it, the core logic of the get()
method is to decide the next step.
As done in the RedisReceiver:
/**
* {@inheritdoc}
*/
public function get(): iterable
{
$redisEnvelope = $this->connection->get();
if (null === $redisEnvelope) {
return [];
}
try {
$envelope = $this->serializer->decode([
'body' => $redisEnvelope['body'],
'headers' => $redisEnvelope['headers'],
]);
} catch (MessageDecodingFailedException $exception) {
$this->connection->reject($redisEnvelope['id']);
throw $exception;
}
return [$envelope->with(new RedisReceivedStamp($redisEnvelope['id']))];
}
You can say: If there's an error (Doctrine try to catch the DbalException for example), so I need to reject the message (maybe because of it's content or other factors).
If the message is rejected, the transport handles the next step.
When we say return [$yourEnvelope->with(new CustomStamp($yourEnvelope['id']);
, we make the message available for the application 🙂
Hope it helps 🙂
7bcaf8b
to
5ccad7f
Compare
This PR was squashed before being merged into the 4.3 branch (closes #11889). Discussion ---------- [Messenger] `get()` usage Hi everyone 👋 As noticed here #11861 (comment) by @xabbuh, a small error has been found in the `get()` documentation. This PR contains a small improvement. Commits ------- 5ccad7f [Messenger] `get()` usage
Thanks @Guikingone! I did the fix suggested by @Leprechaunz while merging. |
Hi everyone 👋
As noticed here #11861 (comment) by @xabbuh, a small error has been found in the
get()
documentation.This PR contains a small improvement.